# minimum cmake version
cmake_minimum_required(VERSION 3.8)
# define Assignment2 as project name
set(PROJECT_NAME Assignment2)
# set project name
project(${PROJECT_NAME})
# set cpp version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED FALSE)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
	# define _CRT_SECURE_NO_WARNINGS with MSVC
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

# add header paths of vendor of CSUGL
include_directories(vendor/CSUGL/vendor/GLFW)
include_directories(vendor/CSUGL/vendor/glad/include)
include_directories(vendor/CSUGL/vendor/glm)
include_directories(vendor/CSUGL/vendor/stb)
include_directories(vendor/CSUGL/vendor/glog/src)
include_directories(vendor/CSUGL/vendor/imgui)
include_directories(vendor/CSUGL/vendor/assimp/include)

# CSUGL configure
set(CSUGL_BUILD_MODEL_LOADER OFF)
	# add sub cmake configure path
add_subdirectory(vendor/CSUGL)
	# add header path of CSUGL
include_directories(vendor/CSUGL/src)

# project configure
include_directories(src/)
if (MSVC)
	# Set the startup project as Assignment2
	set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
endif (MSVC)
# find file recurse
	# source files
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
	# header files
file(GLOB_RECURSE HEADER_FILES src/*.h)
	# shader filse
file(GLOB_RECURSE SHADER_FILES assets/*.glsl)
# set filters of IDE (like VS or XCode)
source_group("Headers" FILES ${HEADER_FILES})
source_group("Sources" FILES ${SOURCE_FILES})
source_group("Shaders" FILES ${SHADER_FILES})
# add executable target with all files used
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${SHADER_FILES})
# set build target (link)
target_link_libraries(${PROJECT_NAME} CSUGL)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
	set(ASSETS_PATH ${CMAKE_SOURCE_DIR}/assets)
	set(TARGET_PATH ${CMAKE_BINARY_DIR})
	message("copy " ${ASSETS_PATH} " to " ${TARGET_PATH})
	add_custom_command(
		TARGET ${PROJECT_NAME} POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_directory ${ASSETS_PATH} ${TARGET_PATH}/assets
		DEPENDS ${PROJECT_SHADERS})
endif()